
typedef struct learner_info_t {
	char ip[16];
	int learner_id;
	int learner_to_acceptor_sid;
	int acceptor_id;
	int acceptor_port;//the port used for connecting to the acceptor.
} learner_info;

typedef struct server_info_t {

	int server_id;
	char ip[16];
	int port;

	int self_sid;
	int successor_sid;

	int multicast_recv_sid;
	int multicast_send_sid;

	int proposer_recv_sid; // only for the multicast sender.

	int learner_tcp_port;

} server_info;

//-------------------------------------------------------------
typedef struct config_info_t {

	int self_id;
	int proposer_id;
	int learner_id;

	int total_num_acceptors;
	int total_num_learners;
	int num_learners_to_connect_to_one_acceptor;

	char multicast_ip[16];
	int multicast_port;

	server_info server_infos[MAX_SERVERS];
	learner_info learner_infos[MAX_LEARNERS];

	int proposer_to_multicaster_port;
	int proposer_to_multicaster_sid;

} config_info;

config_info *config_info_sample;

config_info * config_info_init(int self_id, const char * config_file);
config_info * get_config_info();

void get_ip_port(const char* config_file, config_info * config, const char *match, char flag);
void make_chain(config_info * config);
int read_a_number(const char* config_file, config_info * config, const char * match);

void parse_config_file(const char * config_path, int process_id);
void lp_config_parser(const char * config_path, int proposer_id, int learner_id, int is_proposer);

void get_multicast_address(const char* config_file, config_info * config, const char * match);
void form_ring(config_info *config);
void create_sockets(config_info *config);
void lp_create_sockets(config_info *config, int is_proposer);
void get_multicast_address_for_proposer(const char* config_file, config_info * config, const char * match);
int find_learner_given_ip(config_info *config, char ip[INET_ADDRSTRLEN]);

struct sockaddr_in *GET_SOCKADDR();
